from flask import Flask, request, render_template, url_for, jsonify
from bs4 import BeautifulSoup
import requests
from function import *

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
    return render_template('index.html')

@app.route('/init', methods=['POST'])
def init():
    classification = request.form.get('classification')
    is_first = request.form.get('is_first')
    result = init_spider(classification, is_first)
    return jsonify({'result':result})

@app.route('/spider', methods=['POST'])
def spider():
    classification = request.form.get('classification')
    page_number = request.form.get('page_number')
    value = request.form.get('value')
    result = page_spider(classification, page_number, value)
    return jsonify({'result':result})

@app.route('/test', methods=['GET', 'POST'])
def test():
    return render_template('test.html')


if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=8080)
